package com.chendechao.lib_network.di;

import android.os.Build;

import androidx.annotation.NonNull;



import java.io.IOException;
import java.util.Locale;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 添加头拦截器
 */
public class HttpHeaderInterceptor implements Interceptor {

    /**
     * 自定义拦截器
     * @param chain
     * @return
     * @throws IOException
     */
    @Override
    public Response intercept(@NonNull Chain chain) throws IOException {
        Request original = chain.request();
        //String meid = AppMMKV.INSTANCE.getMEID();
        Request.Builder requestBuilder = original.newBuilder()
                .addHeader("token", "123");
        Request request = requestBuilder.build();
        return chain.proceed(request);
    }


    private String getAcceptLanguage() {
        if (Locale.getDefault().getLanguage().equals(Locale.CHINESE.getLanguage())) {
            if (Locale.getDefault().getCountry().equals(Locale.CHINA.getCountry())) {
                return Locale.getDefault().getLanguage() + "-" + Locale.getDefault().getCountry();
            } else {
                return Locale.getDefault().getLanguage() + "-" + Locale.TAIWAN.getCountry();
            }
        } else if (Locale.getDefault().getLanguage().equals(Locale.ENGLISH.getLanguage())) {
            return Locale.ENGLISH.toString();
        } else {
            return Locale.SIMPLIFIED_CHINESE.getLanguage() + "-"
                    + Locale.SIMPLIFIED_CHINESE.getCountry();
        }
    }
}